#include <string.h>
#include <iostream>
using std::cout;
using std::endl;
class String
{
public:
	String(): _str(new char[1]()) {}
    /* String(){} */

	String(const char* pstr):_str(new char[strlen(pstr) + 1]()) {
		strcpy(_str, pstr);
	}

	//拷贝构造
	String(const String& rhs) :_str(new char[strlen(rhs.c_str()) + 1]())
	{
		strcpy(_str, rhs.c_str());
	}

	String &operator=(const String &rhs){
		if (this != &rhs)
		{
			delete [] _str;
		    _str = new char[strlen(rhs.c_str()) + 1];
		    strcpy(_str, rhs.c_str());
		}
		return *this;
	}

	~String(){
		if (_str)
		{
			delete [] _str;
			_str = nullptr;
		}
	}

	void print(){
		cout << _str << endl;
	}

	size_t length() const{
		return	strlen(_str);
	}

	const char * c_str() const {
		return _str;
	}

private:
	char* _str;
};

void test0(){
    String str;
    str.print();

    String str2("hello");
    cout << str2.length() << endl;
}

int main(void){
    test0();
    return 0;
}
